#-----------------------------------------------------------------------------
# Project:     Multi-Programmer Game Demo
# Name:        Paddle.py
# Purpose:     Controllable Paddle Object
# 
# Authors:     Chris Spooner, Chris La-Roo
# Main Author: Chris Spooner
#
# Created:     11/30/2012
# Copyright:   (c) Chris Spooner 2012
# Licence:     New BSD
#-----------------------------------------------------------------------------
import pygame, math, sys, random
#stuff 
class Paddle():
    def __init__(self, maxSpeed, position):
        self.surface = pygame.image.load("rsc/paddle/paddle.png")
        self.surface = pygame.transform.scale(self.surface, (100, 30))
        self.rect = self.surface.get_rect()
        self.speed = [0,0]
        self.maxSpeed = maxSpeed
        self.place(position)
        
    def  __str__(self):
        pass
#        return "I'm a paddle" + str(self.rect.center)
     
    def place(self, pt):
#        print "I've moved to", pt
        self.rect = self.rect.move(pt)
#        taken from my original ball code
        
    def move(self):
#        print "I've moved", self.speed
        self.rect = self.rect.move(self.speed)
#        taken from my original ball code
    
    def collideWall(self, screenWidth, screenHeight):
#        print "trying to hit edges of screen", screenWidth, screenHeight
        if (self.rect.left < 0 
            or self.rect.right > screenWidth):
            self.speed[0] = self.speed[0]*0
                
    def direction(self, dir):
#        print "moving in direction", dir
        pass
        
    def collidePaddle(self, paddle):
#        print "trying to hit paddle", str(paddle)
        if (self.rect.right > paddle.rect.left 
            and self.rect.left < paddle.rect.right):
            if (self.rect.bottom > paddle.rect.top):
                if (self.rect.left > self.distToPoint(other.rect.center)
                and self.rect.right < self.distToPoint(other.rect.center)):
                    if (self.rect.top > self.distToPoint(other.rect.center)):
                        self.speed[1] = self.speed[1] * -1
                    
#                    taken from my original ball code and edited

    def distToPoint(self, pt):
        x1 = self.rect.center[0]
        x2 = pt[0]
        y1 = self.rect.center[1]
        y2 = pt[1]
        return math.sqrt(((x2-x1)**2)+((y2-y1)**2))
#        taken from my original ball code and edited
        